package com.shy.register;

import com.shy.bean.TestBean;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;

import java.util.Set;

public class ShyBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        RootBeanDefinition beanDefinition = new RootBeanDefinition(TestBean.class);

        beanDefinition.setBeanClassName(TestBean.class.getName());
        MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
        propertyValues.addPropertyValue("name", "shy");
        propertyValues.addPropertyValue("age", 18);
        propertyValues.addPropertyValue("password", "123456");
        registry.registerBeanDefinition("testBean", beanDefinition);

        Set<MethodMetadata> methods = importingClassMetadata.getDeclaredMethods();
        System.out.println(methods);
    }
}
